package com.shiwaixiangcun.customer.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shiwaixiangcun.customer.R;
import com.shiwaixiangcun.customer.glide.ImageDisplayUtil;
import com.shiwaixiangcun.customer.module.houserenting.HouseData;

import java.util.List;

/**
 * Author   Administrator
 * Date     2018/1/16
 * Desc     eg
 *
 * @author Administrator
 */

public class AdapterRenting extends BaseQuickAdapter<HouseData, BaseViewHolder> {
    public AdapterRenting(@Nullable List<HouseData> data) {
        super(R.layout.item_layout_renting, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HouseData item) {
        helper.setText(R.id.tv_house_title, item.getName());


        TextView tvUnitPrice = helper.getView(R.id.tv_unit_price);
        ImageView ivCover = helper.getView(R.id.iv_house_cover);

        TextView tvUnitOther = helper.getView(R.id.tv_unit_other);


        StringBuilder strDesc = new StringBuilder();
        if (item.getStructureName() != null) {
            strDesc.append("/").append(item.getStructureName());
        }
        if (item.getFloor() != null) {
            strDesc.append("/").append(item.getFloor());

        }
        if (item.getBuildingArea() != null) {
            strDesc.append("/").append(item.getBuildingArea()).append("㎡");
        }
        strDesc.deleteCharAt(0);
        helper.setText(R.id.tv_house_desc, strDesc.toString());
        helper.setText(R.id.tv_house_price, item.getPrice());
        switch (item.getTypeValue()) {
            case "rentHouse":
                tvUnitPrice.setVisibility(View.INVISIBLE);
                tvUnitOther.setVisibility(View.INVISIBLE);
                helper.setText(R.id.tv_unit, "元/月");
                break;
            case "saleHouse":
                tvUnitPrice.setVisibility(View.VISIBLE);
                tvUnitOther.setVisibility(View.GONE);
                helper.setText(R.id.tv_unit, "万");
                helper.setText(R.id.tv_unit_price, item.getUnitPrice());
                break;
            default:
                break;

        }
        if (item.getImage() == null || item.getImage().getThumbImageURL() == null) {

            return;
        } else {
            ImageDisplayUtil.showImageView(mContext, item.getImage().getThumbImageURL(), ivCover);
        }

    }
}
